<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      padding: 0;
      margin: 0;
    }
    .container{
      /* position: relative; */
      position: fixed;
      left: 0;top: 0;
      width: 100%;height: 100%;
      background: pink;
    }
    .target{
      position: absolute;
      left: 50%;top: 50%;
      width: 200px;height: 200px;
      background: red;
    }
    .inner{
      position: absolute;
      left: 50%;top: 50%;
      width: 20px;height: 20px;
      background: green;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="target">
      <div class="inner">

      </div>
    </div>
  </div>

  <script lang="javascript">
    // const container = document.querySelector('.container')
    // function createTargets(){
    //   const htmlString = new Array(100000).fill('<div class="target"></div>').join('')
    //   container.html(htmlString)      
    // }

    // function isInViewPort(element){
    //   const viewWidth = window.innerWidth||document.documentElement.clientWidth
    //   const viewHeight = window.innerHeight||document.documentElement.clientHeight
    //   const {top,right,bottom,left} = element.getBoundingClientRect()
    //   return top>=0&&left>=0&&right<=viewWidth&&bottom<=viewHeight
    // }
    // document.documentElement.addEventListener('scroll',()=>{
    //   console.log('scroll!!!');
    //   document.querySelector('.target').each((index,elem)=>{
    //     if(isInViewPort(elem)){
    //       document.querySelector(elem).style.background = 'yellow'
    //     }
    //   })
    // })
  </script>
</body>
</html>